package no.ntnu.fp.server;

import java.io.IOException;
import java.net.SocketTimeoutException;
import no.ntnu.fp.net.co.NaturalJoin;
import no.ntnu.fp.net.co.Connection;

public class ServerListener implements Runnable {
	
	private Server server;
	private Connection listeningPort;
	
	public ServerListener(Server server) {
		
		this.server = server;
		listeningPort = new NaturalJoin(1502);
	}
	
	public void run() {
		listen();
	}
	
	private void listen() {
		
		while(true) {
			
			try {
				Connection connection = listeningPort.accept();
				
				if (connection != null) {
					server.addClient(connection);
				}
			} 
			catch (SocketTimeoutException e) {} 
			catch (IOException e) {}
		}
	}
}
